local tuibeitu = fk.CreateSkill {
  name = "lingling__tuibeitu",
}

Fk:loadTranslationTable{
  ["lingling__tuibeitu"] = "推背图",
  [":lingling__tuibeitu"] = "出牌阶段限一次，你可以扣置两张牌，然后令一名其他角色展示并交给你一张牌，若与你任意扣置牌花色相同，重置此技能。",

  ["#lingling__tuibeitu"] = "推背图：弃两张牌，令一名角色交给你一张牌",
  ["#lingling__tuibeitu-give"] = "推背图：请交给 %src 一张牌",
}

tuibeitu:addEffect("active", {
  anim_type = "offensive",
  prompt = "#lingling__tuibeitu",
  card_num = 2,
  target_num = 1,
  can_use = function (self, player)
    return player:usedSkillTimes(tuibeitu.name, Player.HistoryPhase) == 0
  end,
  card_filter = function (self, player, to_select, selected)
    return #selected < 2 and not player:prohibitDiscard(to_select)
  end,
  target_filter = function (self, player, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= player and not to_select:isNude()
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local suits = table.map(effect.cards, function (id)
      return Fk:getCardById(id).suit
    end)
    --room:throwCard(effect.cards, tuibeitu.name, player, player)
    room:moveCards({ids = effect.cards,from = player,toArea = Card.Processing, moveReason = fk.ReasonJustMove,skillName = tuibeitu.name,proposer = player,moveVisible = false})
    if player.dead or target.dead then return end
    if not target:isNude() then
      local card = room:askToCards(target, {
        min_num = 1,
        max_num = 1,
        include_equip = true,
        skill_name = tuibeitu.name,
        prompt = "#lingling__tuibeitu-give:"..player.id,
        cancelable = false,
      })
      target:showCards(card)
      if table.contains(target:getCardIds("he"), card[1]) and not player.dead then
        room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonGive, tuibeitu.name, nil, true, target)
        player:showCards(effect.cards)
        if table.contains(suits, Fk:getCardById(card[1]).suit) and Fk:getCardById(card[1]).suit ~= Card.NoSuit then
          player:setSkillUseHistory(tuibeitu.name, 0, Player.HistoryPhase)
        end
      end
    end
    room:cleanProcessingArea()
  end,
})

return tuibeitu
